/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package dne.master.tfmtienda.session;

import dne.master.tfmtienda.entity.Usuario;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Noza
 */
@Stateless
public class UsuarioFacade extends AbstractFacade<Usuario> implements UsuarioFacadeLocal {
    @PersistenceContext(unitName = "TFMTienda-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuarioFacade() {
        super(Usuario.class);
    }
    
    @Override
    public Usuario findUsuario(String mail, String pass){
        Usuario res = null;
        Query query = em.createNamedQuery("Usuario.findByUsuarioAndPassword").setParameter("usuario", mail).setParameter("password", pass);
        try{
            res = (Usuario)query.getSingleResult();
        }catch(NoResultException e){
            System.out.println("Error en UsuarioFacade.findUsuario: "+e);
        }
        return res;        
    }
    
}
